#!/usr/bin/env python
# coding: utf-8

# In[1]:


#Importing PulP solver
from pulp import *


# In[2]:


#Inputing the Demand points
demand_points=['Port of Newcastle','Port of Hedland','Port of Vienna','Port of Mina','Port of Antwerp','Port of Santos','Port of Montreal','Port of Vancouver','Port of Shanghai','Port of Hamburg_Czeck','Port of Alexandria','Port of Marseille','Port of Hamburg_Germany','Port of Budapest','Port of Jawaharlal Nehru','Port of Tanjung Priok','Port of Bandar Abbas','Port of Umm Qasr','Port of Haifa','Port of Gioia Tauro','Port of Nagoya','Port of Aqaba','Port of Busan','Port of Shuwaikh','Port of Beirut','Port of Manzanillo','Port of Rotterdam','Port of Salalah','Port of Gaza','Port of Gdansk','Port of Doha','Port of King Abdul Aziz','Port of Jeddah','Port of Bratislava','Port of Durban','Port of Algeciras','Port of Gothenburg','Port of Latakia','Port of Kaohsiung','Port of Bangkok','Port of Mersin','Port of Jebel Ali','Port of Immingham','Port of New York','Port of Los Angeles','Port of Hodeidah']


# In[3]:


demand_points


# In[4]:


#Inputing the Supply Points
supply_points=['Port of Buenos Aires','Port of Antwerp','Port of Santos','Port of Montreal','Port of Vancouver','Port of Shanghai','Buenaventura','Port of Alexandria','Port of Marseille','Port of Hamburg_Germany','Port of Jawaharlal Nehru','Port of Gioia Tauro','Port of Nagoya','Port of Busan','Port of Shuwaikh','Penang Port','Port of Manzanillo','Port of Rotterdam','Port of Lagos','Port of Salalah','Port of Gdansk','Port of Doha','Port of King Abdul Aziz','Port of Jeddah','Port of Singapore','Port of Durban','Port of Algeciras','Port of Bangkok','Port of Jebel Ali','Port of Immingham','Port of New York','Port of Los Angeles','Port of Saigon']


# In[5]:


supply_points


# In[6]:


#Inputing the distances
distance = dict(zip(supply_points,[dict(zip(demand_points, [7087.00,9900.00,9783.00,9420.00,10946.00,1078.00,7874.00,7508.00,11098.00,8105.00,8607.00,7282.00,8105.00,9669.00,9312.00,10113.00,9112.00,9691.00,8747.00,7606.00,10707.00,9083.00,10985.00,9646.00,8704.00,7342.00,7827.00,8169.00,7282.00,8820.00,9355.00,9476.00,8921.00,9771.00,4596.00,6504.00,8275.00,8631.00,12452.00,11538.00,8606.00,9168.00,7877.00,7248.00,8833.00,8382.00])),
dict(zip(demand_points, [13457.00,10946.00,4841.00,7193.00,0.00,6658.00,3300.00,11450.00,11907.00,426.00,3665.00,2339.00,426.00,4726.00,7082.00,9572.00,6882.00,7464.00,3804.00,2663.00,12786.00,4141.00,12424.00,7419.00,3761.00,8663.00,144.00,5939.00,3327.94,1143.00,7125.00,7247.00,4567.00,4829.00,8066.00,1561.00,690.00,3689.00,11343.00,10128.00,3664.00,6938.00,313.00,3827.00,10154.00,5106.00])),
dict(zip(demand_points, [7848.00,8509.00,8705.00,9662.00,6658.00,0.00,6795.00,10037.00,1804.00,7027.00,7529.00,6204.00,7026.00,8591.00,9552.00,10371.00,9351.00,9933.00,7667.00,6528.00,11468.00,8005.00,13783.00,9888.00,7626.00,7223.00,6749.00,8408.00,6360.00,7745.00,9594.00,9716.00,8432.00,8693.00,4838.00,5426.00,7293.00,7553.00,12691.00,11741.00,7528.00,9407.00,6799.00,6148.00,8718.00,8624.00])),
dict(zip(demand_points, [10815.00,13478.00,7098.00,9594.00,3334.00,6796.00,0.00,8696.00,11673.00,3669.00,6196.00,4871.00,3669.00,7258.00,9614.00,12104.00,9414.00,9808.00,6336.00,5195.00,10961.00,6672.00,11234.00,9794.00,6020.00,5899.00,3391.00,8471.00,5165.00,3878.00,9657.00,9778.00,7099.00,7361.00,10468.00,4093.00,3425.00,6220.00,13875.00,12660.00,6195.00,9470.00,3435.00,1729.00,7389.00,7364.00])),
dict(zip(demand_points, [6731.00,7508.00,13490.00,15871.00,11472.00,8403.00,8708.00,0.00,4956.00,11819.00,12322.00,10996.00,11819.00,13383.00,9428.00,7279.00,10381.00,10848.00,12461.00,11320.00,4321.00,12797.00,4517.00,10828.00,12441.00,2814.00,11541.00,10461.00,10365.00,12534.00,10603.00,10668.00,13108.00,13486.00,13733.00,10218.00,12082.00,12345.00,5419.00,7026.00,12320.00,10440.00,11591.00,7051.00,1319.00,11270.00])),
dict(zip(demand_points, [5140.00,3701.00,10444.00,6882.00,11907.00,13268.00,11673.00,4956.00,0.00,12277.00,8365.00,10048.00,12277.00,10330.00,5293.00,2909.00,6557.00,7139.00,8336.00,9335.00,1007.00,7912.00,535.00,7094.00,8385.00,6843.00,11999.00,6270.00,7660.00,12993.00,6814.00,6922.00,7341.00,10432.00,8418.00,10346.00,12539.00,8550.00,597.00,2872.00,8546.00,6627.00,12049.00,10547.00,5688.00,6802.00])),
dict(zip(demand_points, [7610.00,10049.00,9209.00,11561.00,7162.00,5729.00,4387.00,4988.00,8689.00,7531.00,8033.00,6708.00,7531.00,9095.00,11451.00,10635.00,11251.00,11832.00,8173.00,7032.00,7977.00,8509.00,8250.00,11788.00,8130.00,2178.00,7253.00,10308.00,6743.00,8247.00,11494.00,11615.00,8936.00,9197.00,9424.00,5930.00,7794.00,8057.00,9114.00,10711.00,8032.00,11307.00,7303.00,2743.00,3669.00,9474.00])),
dict(zip(demand_points, [9914.00,7404.00,2163.00,3650.00,3665.00,7529.00,6196.00,12322.00,8365.00,4033.00,0.00,1805.00,4034.00,2047.00,3540.00,6030.00,3340.00,3921.00,370.00,1092.00,9243.00,598.00,8882.00,3877.00,427.00,9534.00,3756.00,2397.00,242.00,4750.00,3583.00,3704.00,1024.00,2150.00,5347.00,2103.00,4298.00,571.00,7800.00,6585.00,546.00,3396.00,3806.00,5618.00,11025.00,1563.00])),
dict(zip(demand_points, [11599.00,9088.00,2980.00,5332.00,2339.00,6204.00,4871.00,10996.00,10048.00,2708.00,1805.00,0.00,2708.00,2868.00,5224.00,7714.00,5024.00,5603.00,1946.00,730.00,10928.00,2282.00,10566.00,5558.00,1900.00,8209.00,2430.00,4081.00,1631.00,3425.00,5267.00,5388.00,2709.00,2971.00,7032.00,778.00,2971.00,1830.00,9485.00,8270.00,1806.00,5080.00,2481.00,4293.00,9700.00,3245.00])),
dict(zip(demand_points, [13825.00,11314.00,5209.00,7561.00,426.00,7027.00,3669.00,11819.00,12277.00,0.00,4033.00,2708.00,0.00,5095.00,7451.00,9842.00,7250.00,7832.00,4173.00,3032.00,13155.00,4509.00,12793.00,7788.00,4130.00,9031.00,341.00,6307.00,3595.70,870.00,7493.00,7615.00,4935.00,5197.00,8433.00,1929.00,417.00,4057.00,11711.00,10496.00,4032.00,7306.00,448.00,4195.00,10522.00,5475.00])),
dict(zip(demand_points, [6956.00,4445.00,5619.00,1589.00,7082.00,9552.00,9614.00,9428.00,5293.00,7451.00,3540.00,5224.00,7451.00,5505.00,0.00,3071.00,1265.00,1847.00,3510.00,4510.00,6171.00,3086.00,5810.00,1802.00,3560.00,12946 ,7173.00,1143.00,3243.00,8167.00,1522.00,1630.00,2515.00,5607.00,4714.00,5521.00,7715.00,3725.00,4727.00,3513.00,3720.00,1335.00,7224.00,9036.00,10104.00,1977.00])),
dict(zip(demand_points, [10884.00,8374.00,2268.00,4620.00,2663.00,6528.00,5195.00,11320.00,9335.00,3032.00,1092.00,730.00,3032.00,2154.00,4510.00,7000.00,4310.00,4891.00,1230.00,0.00,10213.00,1568.00,9852.00,4847.00,1189.00,8533.00,2754.00,3367.00,1336.00,3749.00,4553.00,4674.00,1994.00,2256.00,6317.00,1102.00,3295.00,1116.00,8771.00,7555.00,1091.00,4366.00,2805.00,4617.00,10024.00,2533.00])),
dict(zip(demand_points, [4768.00,4088.00,11322.00,7759.00,12786.00,11468.00,10961.00,4321.00,1007.00,13155.00,9243.00,10928.00,13155.00,11208.00,6171.00,3787.00,7435.00,8017.00,9214.00,10213.00,0.00,8790.00,612.00,7972.00,9263.00,6131.00,12877.00,7148.00,8308.00,13871.00,7692.00,7800.00,8219.00,11310.00,9308.00,11224.00,13418.00,9428.00,1498.00,3750.00,9424.00,7505.00,12927.00,9835.00,4992.00,7680.00])),
dict(zip(demand_points, [5141.00,3770.00,10960.00,7398.00,12424.00,13783.00,11234.00,4517.00,535.00,12793.00,8882.00,10566.00,12793.00,10846.00,5810.00,3426.00,7074.00,7655.00,8852.00,9852.00,612.00,8428.00,0.00,7611.00,8901.00,6404.00,12515.00,6786.00,8020.00,13509.00,7330.00,7438.00,7857.00,10949.00,8939.00,10863.00,13056.00,9066.00,1137.00,3388.00,9062.00,7143.00,12565.00,10108.00,5249.00,7318.00])),
dict(zip(demand_points, [8757.00,6246.00,5955.00,310.00,7419.00,9888.00,9794.00,10828.00,7094.00,7788.00,3877.00,5558.00,7788.00,5841.00,1802.00,4873.00,537.00,71,3847.00,4847.00,7972.00,3423.00,7611.00,0,3896.00,13286.00,7510.00,1480.00,3363.00,8504.00,421.00,203.00,2852.00,5944.00,5050.00,5858.00,8051.00,4061.00,6528.00,5315.00,4057.00,562.00,7560.00,9392.00,11504.00,2313.00])),
dict(zip(demand_points, [5076.00,2565.00,7419.00,3856.00,8882.00,10534.00,9839.00,7359.00,3025.00,9251.00,5340.00,7024.00,9251.00,7305.00,2268.00,950.00,3532.00,4113.00,5310.00,6310.00,3903.00,4886.00,3542.00,4069.00,5359.00,9149.00,8973.00,3245.00,5210.00,9970.00,3788.00,3896.00,4315.00,7407.00,5695.00,7321.00,9517.00,5525.00,2461.00,1246.00,5520.00,3601.00,9024.00,9024.00,8035.00,3777.00])),
dict(zip(demand_points, [6715.00,8542.00,10679.00,13061.00,8663.00,7223.00,5899.00,2814.00,6843.00,9031.00,9534.00,8209.00,9031.00,10565.00,12946 ,8920.00,12745.00,13332.00,9673.00,8533.00,6131.00,10011.00,6404.00,13286.00,9631.00,0.00,8736.00,11791.00,8088.00,9730.00,12977.00,13099.00,10419.00,10681.00,10919.00,7413.00,9277.00,9541.00,7268.00,8865.00,9516.00,12790.00,8787.00,4237.00,1490.00,10974.00])),
dict(zip(demand_points, [13548.00,11037.00,4931.00,7284.00,144.00,6749.00,3391.00,11541.00,11999.00,341.00,3756.00,2430.00,341.00,4817.00,7173.00,9663.00,6973.00,7555.00,3894.00,2754.00,12877.00,4231.00,12515.00,7510.00,3852.00,8736.00,0.00,6030.00,3335.00,1058.00,7216.00,7338.00,4658.00,4920.00,8156.00,1652.00,606.00,3780.00,11434.00,10219.00,3755.00,7029.00,282.00,3918.00,10245.00,5197.00])),
dict(zip(demand_points, [9819.00,9048.00,6700.00,8570.00,4653.00,4510.00,7055.00,10321.00,12164.00,5021.00,5524.00,4198.00,5021.00,6586.00,8460.00,9279.00,8260.00,8841.00,5662.00,4523.00,12403.00,6000.00,12691.00,8797.00,5620.00,7506.00,4744.00,7317.00,5500.00,5740.00,8797.00,8624.00,6426.00,6688.00,3746.00,3421.00,5287.00,5548.00,11600.00,10649.00,5523.00,8316.00,4794.00,6516.00,9001.00,6965.00])),
dict(zip(demand_points, [7936.00,5424.00,4476.00,1253.00,5939.00,8408.00,8471.00,10461.00,6270.00,6307.00,2397.00,4081.00,6307.00,4362.00,1143.00,4050.00,943.00,1524.00,2367.00,3367.00,7148.00,1943.00,6786.00,1480.00,2416.00,11791.00,6030.00,0.00,2086.00,7025.00,1186.00,1307.00,1372.00,4464.00,3571.00,4378.00,6418.00,2582.00,5704.00,4490.00,2577.00,999.00,6081.00,7930.00,11137.00,833.00])),
dict(zip(demand_points, [14544.00,12031.00,5926.00,8277.00,1143.00,7745.00,3878.00,12534.00,12993.00,870.00,4750.00,3425.00,870.00,5812.00,8167.00,10657.00,7967.00,8548.00,4889.00,3749.00,13871.00,5224.00,13509.00,8504.00,4847.00,9730.00,1058.00,7025.00,4119.00,0.00,8213.00,8334.00,5654.00,5915.00,9152.00,2649.00,452.00,4775.00,12430.00,11215.00,4751.00,8025.00,1166.00,4316.00,11242.00,6190.00])),
dict(zip(demand_points, [8477.00,5966.00,5662.00,140.00,7125.00,9594.00,9657.00,10603.00,6814.00,7493.00,3583.00,5267.00,7493.00,5547.00,1522.00,4592.00,355.00,490.00,3553.00,4553.00,7692.00,3423.00,7330.00,421.00,3602.00,12977.00,7216.00,1186.00,3139.00,8213.00,0.00,219.00,2558.00,5650.00,4757.00,5564.00,7757.00,3767.00,6248.00,5034.00,3763.00,187.00,7267.00,9392.00,11279.00,2019.00])),
dict(zip(demand_points, [8585.00,6074.00,5783.00,108.00,7247.00,9716.00,9778.00,10668.00,6922.00,7615.00,3704.00,5388.00,7615.00,5669.00,1630.00,4700.00,365.00,274.00,3674.00,4674.00,7800.00,3250.00,7438.00,203.00,3724.00,13099.00,7338.00,1307.00,3203.00,8334.00,219.00,0.00,2680.00,5771.00,4878.00,5685.00,7879.00,3889.00,6356.00,5142.00,3885.00,389.00,7388.00,9222.00,11344.00,2141.00])),
dict(zip(demand_points, [8890.00,6379.00,3103.00,2626.00,4567.00,8432.00,7099.00,13108.00,7341.00,4935.00,1024.00,2709.00,4935.00,2989.00,2515.00,5005.00,2315.00,2897.00,995.00,1994.00,8219.00,571.00,7857.00,2852.00,1044.00,10419.00,4658.00,1372.00,828.00,5654.00,2558.00,2680.00,0.00,3092.00,4323.00,3006.00,5200.00,1209.00,6775.00,5561.00,1205.00,2371.00,4708.00,6521.00,11927.00,539.00])),
dict(zip(demand_points, [4717.00,2206.00,7788.00,4226.00,9252.00,10863.00,10507.00,7007.00,2692.00,9621.00,5710.00,7391.00,9621.00,7674.00,2637.00,591.00,3902.00,4483.00,5680.00,6680.00,3570.00,5256.00,3208.00,4439.00,5729.00,15120.00,9343.00,3614.00,5531.00,10337.00,4158.00,4266.00,4685.00,7777.00,6025.00,7691.00,9883.00,5894.00,2126.00,917.00,5890.00,3971.00,9393.00,11205.00,7683.00,4146.00])),
dict(zip(demand_points, [6531.00,5302.00,7426.00,4824.00,8066.00,4838.00,10468.00,13733.00,8418.00,8433.00,5347.00,7032.00,8433.00,7312.00,4714.00,5533.00,4514.00,5095.00,5318.00,6317.00,9308.00,4894.00,8939.00,5050.00,5367.00,10919.00,8156.00,3571.00,7346.00,9152.00,4757.00,4878.00,4323.00,7415.00,0.00,6834.00,8698.00,5534.00,7930.00,6941.00,5530.00,4572.00,8207.00,9902.00,12410.00,3786.00])),
dict(zip(demand_points, [11896.00,9385.00,3279.00,5631.00,1561.00,5426.00,4093.00,10218.00,10346.00,1929.00,2103.00,778.00,1929.00,3165.00,5521.00,8011.00,5321.00,5902.00,2242.00,1102.00,11224.00,2579.00,10863.00,5858.00,2200.00,7413.00,1652.00,4378.00,2004.00,2649.00,5564.00,5685.00,3006.00,3267.00,6834.00,0.00,2195.00,2127.00,9782.00,8567.00,2102.00,5377.00,1703.00,3515.00,8922.00,3545.00])),
dict(zip(demand_points, [5436.00,3109.00,8664.00,5102.00,10128.00,11741.00,12660.00,7026.00,2872.00,10496.00,6585.00,8270.00,10496.00,8550.00,3513.00,1449.00,4778.00,5359.00,6556.00,7555.00,3750.00,6132.00,3388.00,5315.00,6605.00,8865.00,10219.00,4490.00,6341.00,11215.00,5034.00,5142.00,5561.00,8653.00,6941.00,8567.00,10763.00,6770.00,2307.00,0.00,6766.00,4847.00,10269.00,12081.00,7730.00,5022.00])),
dict(zip(demand_points, [8290.00,5779.00,5475.00,327.00,6938.00,9407.00,9470.00,10440.00,6627.00,7306.00,3396.00,5080.00,7306.00,5360.00,1335.00,4405.00,173.00,606.00,3366.00,4366.00,7505.00,2942.00,7143.00,562.00,3415.00,12790.00,7029.00,999.00,2975.00,8025.00,187.00,389.00,2371.00,5463.00,4572.00,5377.00,7573.00,3580.00,6063.00,4847.00,3576.00,0.00,7080.00,8918.00,11116.00,1832.00])),
dict(zip(demand_points, [13598.00,11088.00,4982.00,7334.00,313.00,6799.00,3435.00,11591.00,12049.00,448.00,3806.00,2481.00,448.00,4868.00,7224.00,9714.00,7023.00,7605.00,3944.00,2805.00,12927.00,4282.00,12565.00,7560.00,3903.00,8787.00,282.00,6081.00,3399.00,1166.00,7267.00,7388.00,4708.00,4970.00,8207.00,1703.00,714.00,3830.00,11485.00,10269.00,3804.00,7080.00,0.00,3968.00,10295.00,5247.00])),
dict(zip(demand_points, [9689.00,12899.00,6839.00,9168.00,3827.00,6148.00,1729.00,7051.00,10547.00,4195.00,5618.00,4293.00,4195.00,6728.00,9036.00,11525.00,8862.00,9417.00,5756.00,4617.00,9835.00,6104.00,10108.00,9392.00,5715.00,4237.00,3918.00,7930.00,5196.00,4316.00,9392.00,9222.00,6521.00,6830.00,9902.00,3515.00,3864.00,5642.00,10972.00,12081.00,5617.00,8918.00,3968.00,0.00,5734.00,7105.00])),
dict(zip(demand_points, [6466.00,7885.00,12171.00,14552.00,10154.00,8718.00,7389.00,1319.00,5688.00,10522.00,11025.00,9700.00,10522.00,12056.00,10104.00,7910.00,11057.00,11524.00,11048.00,10024.00,4992.00,11501.00,5249.00,11504.00,11122.00,1490.00,10245.00,11137.00,9280.00,11242.00,11279.00,11344.00,11927.00,12158.00,12410.00,8922.00,10789.00,11049.00,6129.00,7730.00,11024.00,11116.00,10295.00,5734.00,0.00,12465.00])),
dict(zip(demand_points, [4876.00,2659.00,8528.00,4964.00,9991.00,11334.00,12523.00,2659.00,1997.00,10360.00,6448.00,8133.00,10360.00,8413.00,3376.00,993.00,4640.00,5221.00,6418.00,7418.00,2881.00,5994.00,2520.00,5177.00,6467.00,15842.00,10082.00,4353.00,6368.00,11079.00,4896.00,5004.00,5423.00,8516.00,6577.00,8430.00,10626.00,6633.00,1434.00,870.00,6628.00,4709.00,10133.00,11986.00,593.00,4884.00]))]))


# In[7]:


distance


# In[8]:


#Inputing the Plastic Demand
plastic_demand=dict(zip(demand_points, [1836916.4000,10483669.4300,644911.8000,1879080.0000,3539318.5900,390810.0000,5879772.8900,1371830.8000,43094265.7100,12214338.7000,49140.0000,15997815.6400,19755457.9100,2248890.0000,60676592.4000,9150002.3600,163590.0000,10920.0000,1890.0000,2183770.3500,95804686.5900,2055060.0000,69461024.6600,3406764.9300,30240.0000,3304560.0000,1082857.2700,210.0000,0.0000,1608748.3500,3377010.0000,4663931.3800,1608768.6200,6011319.5800,1494150.0000,10413482.9200,1099678.9300,11970.0000,5584087.7400,20849268.5100,9017750.2800,264810.0000,9106539.1300,51496957.2400,20905903.4500,2100.0000]))


# In[9]:


plastic_demand


# In[10]:


#Inputing the Plastic Supply
plastic_supply=dict(zip(supply_points, [3484952.6435,3021067.5020,7945692.0017,1637839.3004,7771532.4984,234997919.6606,2509165.8953,731840.0219,6474235.9733,16669297.2185,10078880.5696,9565903.5174,13163659.9622,44795024.7538,887965.8933,12318631.8073,6272914.5326,2745849.6660,243946.6740,665974.4200,4350000.5481,1775931.7866,9520988.2609,5352440.4517,20157761.1392,1219733.3699,5144723.8347,19037885.5204,3995846.5198,5051019.5284,27723150.5426,19323708.4517,5599378.0942])) 


# In[11]:


plastic_supply


# In[12]:


# Set Problem Variables
prob = LpProblem("Transportation", LpMinimize)


# In[13]:


prob


# In[14]:


# Set Problem Variables
routes = [(i,j) for i in supply_points for j in demand_points]


# In[15]:


routes


# In[16]:


# Decision Variables
X = LpVariable.dicts("ShipmentAmount",(supply_points, demand_points),0)


# In[17]:


X


# In[18]:


# Objective Function
prob += sum(X[i][j]*distance[i][j] for (i,j) in routes)


# In[19]:


prob


# In[20]:


# Constraints
for j in demand_points:
    prob += sum(X[i][j] for i in supply_points) >= plastic_demand[j]
    
prob


# In[21]:


# Constraints
for i in supply_points:
    prob += sum(X[i][j] for j in demand_points) == plastic_supply[i]
prob


# In[22]:


prob.solve()

print("Status:", LpStatus[prob.status])

for v in prob.variables():
    if v.varValue > 0:
        print(v.name, "=", v.varValue)

print("Total kilogram_miles =", value(prob.objective))


# In[ ]:




